<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p>
        绘制图形
    </p>
    <input type="text">
    <input type="button" value="计算" onclick="getResult()">
    <span></span>
    <span></span>
    <script>
        function getResult() {
            let row = document.querySelector('input').value;
            let str = ''
            for (let i = 0; i < row; i++) {
                for (let j = 0; j < row - i; j++) {
                    str += '&ensp;'
                }
                for (let k = 0; k < 2 * i - 1; k++) {
                    str += '*'
                }
                str += '<br/>'
            }
            document.querySelector('span').innerHTML = str;
            for (let i = row; i > 0; i--) {
                for (let j = 0; j < row - i; j++) {
                    str += '&ensp;'
                }
                for (let k = 0; k < 2 * i - 1; k++) {
                    str += '*'
                }
                str += '<br/>'
                document.querySelector('span').innerHTML = str;
            }
        }
    </script>
</body>

</html>